package com.restart.game.common.util.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Random;

/**
 * @author ReStartLin
 * @data 2018/12/24 16:14
 * @classDesc: 功能描述:
 */
public class FieldFilter {
    public static final Logger logger = LoggerFactory.getLogger(FieldFilter.class);
    /**
     * 检查标题是否含有违禁字 通过为true
     * @param title
     * @return
     */
    public static boolean checkTitle(String title) {
        String[] titles = NoticeFilterConf.getInstance().getPs();
        for (String s : titles) {
            if (title.contains(s)) {
                logger.info("标题含有:{}被驳回",s);
                return false;
            }
        }
        return true;
    }

    //检查游戏名字
    public static boolean checkName(String name) {
        Map<String, Integer> titleMap = NoticeFilterConf.getInstance().getTitleMap();
        return !titleMap.containsKey(name);
    }

    public static String changeContent(String s) {
        if (s.contains("97973")) {
            s = s.replaceAll("97973", "");
        }
        if (s.contains("手游网")) {
            s = s.replaceAll("手游网", "");
        }
        if (s.contains("style=\"color: #ff0000;\"")) {
            s = s.replaceAll("style=\"color: #ff0000;\"", "");
        }
        if (s.contains("style=\"color: #0000ff;\"")) {
            s = s.replaceAll("style=\"color: #0000ff;\"", "");
        }
        return s;
    }

    public static boolean checkContent(String s) {
        if (s.contains("小编为大家带来的全部")||s.contains("交流推荐群")
                ||s.contains("交流群")||s.contains("二维码")
                ||s.contains("全民手游攻略")) {
            return true;
        }
        return false;
    }

    public static String getWb() {
        String[] lasts = NoticeFilterConf.getInstance().getLasts();
        Random random = new Random();
        int i = random.nextInt(lasts.length);
        return lasts[i];
    }

    public static String getTb() {
        String[] frists  = NoticeFilterConf.getInstance().getFrists();
        Random random = new Random();
        int i = random.nextInt(frists.length);
        return frists[i];
    }
}
